from typing import *


class Solution:

    def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
        ans = [0] * len(temperatures)
        s = []
        for i, v in enumerate(temperatures):
            while len(s) > 0 and v > temperatures[s[-1]]:
                j = s.pop()
                ans[j] = i - j
            s.append(i)

        return ans